<template>
	<view>
		<!-- 热销商品 -->
		<view class="flex justify-between" style="flex-wrap: wrap;margin:0 30rpx;">
			<block v-for="(item,index) in list" :key="index">
				<commonItem :item="item" :color="'#f25204'"></commonItem>
			</block>
		</view>
		<u-empty v-if="list.length == 0"
		        mode="list"
		        icon="http://cdn.uviewui.com/uview/empty/list.png"
				width="150px"
				height="150px"
				text="列表为空"
				textSize="18"
		>
		</u-empty>
		<view style="padding-bottom: 100rpx;">
			<u-loadmore v-if="loading" status="loading" />
			<u-loadmore v-if="isLastPage" status="nomore" />
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				page:1,
				limit:10,
				list:[],
				isLastPage: false,
				loading: false,
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getcollectList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getcollectList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getcollectList();
			} else {
				this.isLastPage = true
			}
		},
		methods:{
			getcollectList() {
				let parmar = {
					page: this.page,
					limit: this.limit,
				}
				this.$api.collect_list(parmar).then(res => {
					if (res.code === 1) {
						 this.list = [...this.list, ...res.data]
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>